package com.yanggeng.demo.beginnerguidedemo.bean.db;

import com.yanggeng.demo.beginnerguidedemo.utils.GreenDaoUtils;

import org.greenrobot.greendao.query.QueryBuilder;

import java.util.List;

/**
 * Created by yanggeng on 2017/7/21.
 */

public class BillDaoUtil {
    private static BillBeanDao billBeanDao = GreenDaoUtils.getInstance().getDaoSession().getBillBeanDao();
    private static ImageAddrBeanDao imageAddrBeanDao = GreenDaoUtils.getInstance().getDaoSession().getImageAddrBeanDao();

    public static void insert(BillBean billBean, List<ImageAddrBean> images) {
        long billId = billBeanDao.insert(billBean);
        if(billId != -1 && images != null) {
            for(int i = 0; i < images.size(); i ++) {
                ImageAddrBean imageAddrBean = images.get(i);
                imageAddrBean.setBillid(billId);
                imageAddrBeanDao.insert(imageAddrBean);
            }
        }
    }

    public static List<BillBean> findAll() {
        return billBeanDao.loadAll();
    }

//    public static List<BillBean> findByDate(long startDate, long endDate) {
//        QueryBuilder queryBuilder = billBeanDao.queryBuilder();
//        return queryBuilder.where(BillBeanDao.Properties.Date.between(startDate, endDate)).orderAsc(BillBeanDao.Properties.Id).build().list();
//    }

}
